package com.xyy.saas.payment.adpater.fumin.util;

import com.alibaba.fastjson.JSONObject;
import com.fbank.openapi.sdk.config.Configuration;
import com.fbank.openapi.sdk.service.AbstractOpenApiService;
import com.xyy.saas.payment.adpater.fumin.spring.SpringConfiguration2;
import java.nio.charset.StandardCharsets;

public class VerifyAndDecryptUtil2 extends AbstractOpenApiService {
    private static VerifyAndDecryptUtil2 obj = null;

    /**
     * 获取对象
     */
    public static VerifyAndDecryptUtil2 get() {
        if(obj != null) {
            return obj;
        }

        synchronized(VerifyAndDecryptUtil2.class) {
            if(obj == null) {
                obj = new VerifyAndDecryptUtil2();
            }
        }

        return obj;
    }

    /**
     * 验签&解密
     */
    public String verifyAndDecrypt(Configuration configuration, JSONObject data) throws Exception {
        return super.verifyAndDecrypt(null, configuration, null, data.toJSONString().getBytes(StandardCharsets.UTF_8));
    }

    /**
     * 私有化构造方法
     */
    private VerifyAndDecryptUtil2() {}

    public static void main(String[] args) throws Exception {
        JSONObject data = JSONObject.parseObject("{\n" +
                "    \"data\":\"yptPdEQbnfDSRgPFzuh01/3eydivzV2oD1vCDrYcdGCyvWZSEIuDQeS0rcWA26k2yfKCPQABb7wBRfkuYZqabQntyvBT990+XFXjno5jI7t0UHx3nBZJO9F/lRAGl7HmRcgpIhRpAn0s0hUlEdSPfPQTickF3go9HhChERz1S+ZVkH0anqeB3Qr/DTgIp4hPk/j4CtiT/UGhwf6Gx5sB44z8tGDDMjl3mwtkymxmYtiJhaiFDnf5WpWqlSdgTHL5ak25O6DH0jpWgDK+aQPIhQ==\",\n" +
                "    \"encryptType\":\"RSAV2\",\n" +
                "    \"merchantNo\":\"8808001002996654\",\n" +
                "    \"randomKeyEncrypt\":\"27g1SB5WEKfKfSLFP9wMXMl8vsqsT+ac5T8g3RwqDVo60YQnCc619g31Cf+x6+3hMVP7GPrjUNOh7h/kM1fTlNueosI/I2MaEh2AXHe5ON1jx25pmkfMT6FyTE1xDWS0+uyIUirSbv6dQ5PB3KYx/uTmk0V4bLWHMyQNqQ0wr/MAM+hmVt1CoEVqAdfCtbYUNzfM2ZmLBszrhHrahIZyJ7iL5Ick9xIUeYpD722OMz2rsM8ff/+u8oZOipGk2WwgirbSTWAdcGDqqAlUY1q5pSQ4XK6z2Vsr8JYwouPyfW0aJ+dcurXMMgQgRmA0LdaAbusk5Ecas2OmHmnS4/Pm+g==\",\n" +
                "    \"signData\":\"naT9BzeywGA7adNs6CVmGQniTxija5btfp/oSyVocAqCfCcf4EY9qlJ8ouMGUj06OTDTCH8s/4sBSVmlEUxZGO8ogHBKQXxIWNIhLBDST9GcbDkJbZKncqARKiphG+wnetAYDjgpCeGZNsWDKOr/SQYYrsWg88KYABY0mmRH5fOcHn/MvTKrpEuJpY9OORTF36fViO8fK3AxXzkUdpCNRrUpkl9rt9huHlJagetGSNt6xzvEtK/avr9ClVDnrICgqoLOCYNUbVRQm2ATRDi9WOD2/bGiM79KcF41dDbeauXPmBbevjXgLUcPuB3hngmvdeSZ3pH127whrz5PxqKVKw==\",\n" +
                "    \"signType\":\"RSAV2\",\n" +
                "    \"timestamp\":1654510710042\n" +
                "}");
        System.out.println(get().verifyAndDecrypt(new SpringConfiguration2(), data));
    }
}
